Skip to content

Add all the supporting infrastructure for removeUnused mode#203

Merged
bulldozer-bot[bot] merged 15 commits intodevelopfrom
okelvin/remove-unused-mode
Oct 21, 2025
Merged

Add all the supporting infrastructure for removeUnused mode#203
bulldozer-bot[bot] merged 15 commits intodevelopfrom
okelvin/remove-unused-mode

Conversation

@kelvinou01
Copy link
Copy Markdown
Contributor

@kelvinou01 kelvinou01 commented Oct 17, 2025

Before this PR

See #173 for background

FLUP to #192 and #200

We are working on -PerrorProneRemoveUnused, a mode which removes all unused suppressions. This is the penultimate PR which brings in all the infrastructure required to support removeUnused mode:

  • New modes and interferences (removeUnused leads to UnsupportedOperationException for the time being)
  • ReportedFixCache to encapsulate creating and reporting new suppression fixes. Note that this uses state.reportMatch, c.f. the old mechanism of returning a populated Description from interceptDescription
  • A new SuppressibleErrorProne bugchecker, used to prevent infinite recursion from ReportedFixCache calling state.reportMatch
  • Various utils

The actual implementation for removeUnused will be brought in the next PR for ease of review.

After this PR

==COMMIT_MSG==
Add the removeUnused mode and it's interferences
==COMMIT_MSG==

Possible downsides?

@changelog-app
Copy link
Copy Markdown

changelog-app bot commented Oct 17, 2025

Generate changelog in changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

Add the removeUnused mode and it's interferences

Check the box to generate changelog(s)

  • Generate changelog entry

@changelog-app
Copy link
Copy Markdown

changelog-app bot commented Oct 17, 2025

Successfully generated changelog entry!

What happened?

Your changelog entries have been stored in the database as part of our migration to ChangelogV3.

Need to regenerate?

Simply interact with the changelog bot comment again to regenerate these entries.


📋Changelog Preview

✨ Features

  • Add the removeUnused mode and it's interferences (#203)

@kelvinou01 kelvinou01 changed the title Add the removeUnused mode and it's interferences Add all the supporting infrastructure for removeUnused Oct 17, 2025
return EntryStream.of(CommonOptions.this.extraErrorProneCheckOptions())
.append(other.extraErrorProneCheckOptions())
.toMap();
.collect(Collectors.toMap(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to specify how we collect duplicate keys here, or else we get an error

Comment on lines +43 to +46
@Override
public Map<String, String> extraErrorProneCheckOptions() {
return Map.of("SuppressibleErrorProne:Mode", "RemoveUnused");
}
Copy link
Copy Markdown
Contributor Author

@kelvinou01 kelvinou01 Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be used in VisitorStateModifications to branch to the removeUnused procedure.

Comment on lines +36 to +39
@Override
public Map<String, String> extraErrorProneCheckOptions() {
return Map.of("SuppressibleErrorProne:Mode", "Apply");
}
Copy link
Copy Markdown
Contributor Author

@kelvinou01 kelvinou01 Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To maintain parity with RemoveUnusedMode. Also, potentially a way to move mode interference logic into VisitorStateModifications in the future (see #180)

Comment on lines +53 to +54
"SuppressibleErrorProne:Mode",
"RemoveRollout");
Copy link
Copy Markdown
Contributor Author

@kelvinou01 kelvinou01 Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To maintain parity with RemoveUnusedMode. Also, potentially a way to move mode interference logic into VisitorStateModifications in the future (see #180)

Comment on lines +40 to +43
@Override
public Map<String, String> extraErrorProneCheckOptions() {
return Map.of("SuppressibleErrorProne:Mode", "Suppress");
}
Copy link
Copy Markdown
Contributor Author

@kelvinou01 kelvinou01 Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To maintain parity with RemoveUnusedMode. Also, potentially a way to move mode interference logic into VisitorStateModifications in the future (see #180)

@kelvinou01 kelvinou01 changed the title Add all the supporting infrastructure for removeUnused Add all the supporting infrastructure for removeUnused mode Oct 17, 2025
import java.util.Map;
import java.util.Set;

public final class RemoveUnusedAndApplyingInterference extends SpecificModeInterference {
Copy link
Copy Markdown
Contributor

@CRogers CRogers Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this identical to the suppressing + applying interference? What happens when we have suppressing + applying + removeUnused?

I'm honestly not convinced that this interference concept was necessary (mea culpa) - I think we may have been able to always use -XepPatchChecks: to enable patching on every bugchecker and always send a list of checks that need patching to VisitorStateModifications, which would remove fixes if it is not to be patched (when suppressing/applying/etc).

If we still need to keep interferences, I think we could use the ModeInterference interface directly, return all of suppress/apply/removeUnused as interfering if they have been enabled. The combine all of them together in interfere (and only have one interference between all three).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I think about it, if we are reporting rollout suppressions with SuppressibleErrorProne bugchecker, I think we can get rid of PreferPatchChecks entirely. -XepPatchChecks will retain it's original semantics of actually applying the autofixes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed privately, let's consolidate the duplicate logic to a ApplyingAndSuppressingOrRemoveUnusedInterference

@kelvinou01 kelvinou01 force-pushed the okelvin/remove-unused-mode branch from e898d04 to 9de5225 Compare October 20, 2025 16:24
* Initialize a {@code LazySuppressionFix} on {@code declaration}, choosing which suppressions to keep with
* {@code filterExisting}.
*/
@SuppressWarnings("PreferSafeLoggableExceptions") // It doesn't matter in our internal codebases
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably disable it in the build.gradle for this project.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think the it shouldn't even suggest this unless safe-logging is on the classpath. Not sure why it would be.

Copy link
Copy Markdown
Contributor Author

@kelvinou01 kelvinou01 Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it's being suggested everywhere. Maybe the safe logging errorprones should live in safe-logging instead after #178 is out


@Override
public Map<String, String> extraErrorProneCheckOptions() {
return Map.of("SuppressibleErrorProne:Mode", "Apply");
Copy link
Copy Markdown
Contributor

@CRogers CRogers Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would at least make "SuppressibleErrorProne:Mode" a constant across all these files.

It could actually be a higher level concept, ie have it's own method on CommonOptions or - even better - the modes framework could automatically add check option based on the modes in use, meaning this isn't even necessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it a constant for now, and tweak the concept in the next PR

@CRogers
Copy link
Copy Markdown
Contributor

CRogers commented Oct 21, 2025

:+1L

@CRogers
Copy link
Copy Markdown
Contributor

CRogers commented Oct 21, 2025

👍

@bulldozer-bot bulldozer-bot bot merged commit 82bacbf into develop Oct 21, 2025
5 checks passed
@bulldozer-bot bulldozer-bot bot deleted the okelvin/remove-unused-mode branch October 21, 2025 16:54
@autorelease3
Copy link
Copy Markdown

autorelease3 bot commented Oct 21, 2025

Released 2.22.0

@kelvinou01 kelvinou01 mentioned this pull request Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants